from django.db import models
import datetime
from tagging.fields import TagField

PRIORITY_CHOICES = (
    ('N','None'),
    ('L','Low'),
    ('R','Regular'),
    ('H','High'),
    ('C','Critical'),
)

# Create your models here.

class QuickThought(models.Model):
    text = models.TextField()
    tags = TagField(blank=True)
    created = models.DateField(editable=False)
    updated = models.DateTimeField(editable=False)

    def __str__(self):
        return self.text
    def save(self):
        if not self.id:
            self.created = datetime.date.today()
        self.updated = datetime.datetime.now()
        super(QuickThought, self).save()

    class Meta:
        ordering = ['-updated']
    class Admin:
        pass

class BlogEntry(models.Model):
    above_the_fold = models.TextField()
    title = models.CharField(max_length=256)
    text = models.TextField()
    footnotes = models.TextField(blank=True)
    active_after = models.DateTimeField('Active As Of', default=datetime.datetime.now)
    tags = TagField(blank=True)
    created = models.DateField(editable=False)
    updated = models.DateTimeField(editable=False)

    def __str__(self):
        return self.title

    def save(self):
        if not self.id:
            self.created = datetime.date.today()
        self.updated = datetime.datetime.now()
        super(BlogEntry, self).save()

    class Meta:
        ordering = ['-active_after']
    class Admin:
        list_display = ('title','active_after')
        list_filter = ('title', 'active_after')
        search_fields = ('title')
        js = ('http://code.jquery.com/jquery-latest.pack.js',)

class Event(models.Model):
    tags = TagField(blank=True)
    title = models.CharField(max_length=256)
    text = models.TextField()
    start = models.DateTimeField()
    end = models.DateTimeField()
    priority = models.CharField(max_length=1, choices=PRIORITY_CHOICES)
    attendees = models.TextField()
    private = models.BooleanField()
    created = models.DateField(editable=False)
    updated = models.DateTimeField(editable=False)

    def __str__(self):
        return self.title
    def save(self):
        if not self.id:
            self.created = datetime.date.today()
        self.updated = datetime.datetime.now()
        super(Event, self).save()

    class Meta:
        ordering = ['-updated']
    class Admin:
        pass

class Bookmark(models.Model):
    title = models.TextField()
    link = models.URLField()
    hits = models.IntegerField(default=0, editable=False)
    tags = TagField(blank=True)
    created = models.DateField(editable=False)
    updated = models.DateTimeField(editable=False)

    def __str__(self):
        return self.title
    def save(self):
        if not self.id:
            self.created = datetime.date.today()
        self.updated = datetime.datetime.now()
        super(Bookmark, self).save()

    class Meta:
        ordering = ['-updated']
    class Admin:
        pass
